import {request} from "../request";
import {utils} from "../../common/utils";

//1 获取字典表数据
export function getDictList({name,code,enabled,start,end}) {
    return request({
        url: '/sys/dict/query',
        method: 'get',
        params:{
            name,
            code,
            enabled,
            start,
            end
        }
    })
}

//2.0 添加字典目录
export function addDict({name, code, parentId, enabled, remark,}) {
    return request({
        url: '/sys/dict/add',
        method: 'post',
        data: {name, code, parentId, enabled, remark}
    })
}

//2.1 添加字典子项
export function addChildren({parentId, children}) {
    return request({
        url: '/sys/dict/add-children',
        method: 'post',
        data:{
            id: parentId,
            children:children
        }
    })
}

//3.删除字典数据
export function deleteDict(ids) {
    let strUrl = utils.joinArrayReqParam(ids,'ids');
    return request({
        url: '/sys/dict/delete' + strUrl,
        method: 'delete'
    })
}

//4.修改字典
export function updateDict({id, name, code, parentId, enabled, remark}) {
    return request({
        url: '/sys/dict/update',
        method: 'put',
        data: {id, name, code, parentId, enabled, remark}
    })
}

//13、获取字典的类型
export function getDictTypes(){
    return request({
        url: '/sys/dict/types',
        method: 'get'
    })
}

//14、导出字典表数据
export function exportDict(){
    return request({
        url: '/sys/dict/export',
        method: 'get',
        // responseType: 'blob'已弃用
    })
}

//15、查询同级下是否存在相同字典
export function hasSomeSiblingDict({id,name,parentId}){
    return request({
        url: '/sys/dict/has-some-sibling',
        method: 'get',
        params:{
            id,
            name,
            parentId
        }
    })
}

//16.查询顶级记录是否存在相同编码
export function hasSomeSiblingCode({id,code}){
    return request({
        url: '/sys/dict/has-some-sibling-code',
        method: 'get',
        params: {
            id,
            code
        }
    })
}
